package com.lagou.cl.core;

import com.lagou.cl.pojo.Mapper;

import java.util.List;


public class StandardService implements Lifecycle {

	private StandardEngine standardEngine;

	private List<Connector> connectors;

	public StandardService(StandardEngine standardEngine, List<Connector> connectors) {
		this.standardEngine = standardEngine;
		this.connectors = connectors;
	}

	@Override
	public void init() {

		//初始化engine
		if (standardEngine != null) {
			standardEngine.init();
		}

		//初始化connector(一个service中可以有多个connector)
		if (connectors != null && connectors.size() > 0) {
			Mapper.mappedConnector.addAll(connectors);
		}
	}

	@Override
	public void start() {
		if (standardEngine != null) {
			standardEngine.start();
		}
	}

	@Override
	public String toString() {
		return "com.lagou.cl.core.StandardService{" +
				"standardEngine=" + standardEngine +
				", connectors=" + connectors +
				'}';
	}
}
